<?php

namespace App\Jobs;

use App\Mail\Test;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;

class SendMail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //测试邮件发送与短信发送
        $data = [
            'title' => '测试邮件发送',
            'content' => '系统产生了一个错误，请尽快查看',
        ];
        //暂时写死一个接收邮件，多个的话 explode 再遍历即可
        $recipient = env('MAIL_RECIPIENT');
        //邮件发送写入任务队列 指定 emails 队列
        Mail::to($recipient)->queue((new Test($data))->onQueue('emails'));
    }
}
